package com.ctbri.gui;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.ctbri.util.SwingConsole;

public class Ex22 extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JSlider redSlider = new JSlider(0, 255, 1);
	private JSlider greenSlider = new JSlider(0, 255, 1);
	private JSlider blueSlider = new JSlider(0, 255, 1);
	Color color = new Color(0, 0, 0);
	private JPanel panel = new JPanel();
	private ChangeListener cl = new ColorChangeListener();
	
	public Ex22() {
		JPanel southPanel = new JPanel();
		BoxLayout boxLayout = new BoxLayout(southPanel, BoxLayout.Y_AXIS);
		southPanel.setLayout(boxLayout);
		southPanel.add(redSlider);
		southPanel.add(greenSlider);
		southPanel.add(blueSlider);
		redSlider.addChangeListener(cl);
		greenSlider.addChangeListener(cl);
		blueSlider.addChangeListener(cl);
		add(panel);
		add(southPanel, BorderLayout.SOUTH);
	}
	
	class ColorChangeListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent e) {
			panel.setBackground(new Color(redSlider.getValue(), greenSlider.getValue(), blueSlider.getValue()));
		}
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new Ex22(), 200, 200);
	}
}
